﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;
using System.IO;
using System.Web.UI.WebControls;
using GMS.BIZ;


namespace GMS.BIZ
{
    public class Library
    {

        #region no static function
        /// <summary>
        /// 添加公司
        /// </summary>
        /// <param name="companyName">公司名</param>
        /// <returns></returns>
        public string AddCompany(string companyName)
        {
            //检查companyName是否为空
            if (companyName == null || companyName == string.Empty)
                return ErrorMessage.FieldEmpty;

            GMS.ORM.Model.GCompanyLib myGCompanyLib = new GMS.ORM.Model.GCompanyLib();
            GMS.ORM.DAL.GCompanyLib optGCompanyLib = new GMS.ORM.DAL.GCompanyLib();
            //判断公司名是否存在
            DataSet ds = optGCompanyLib.GetList("name='" + companyName + "'");
            if (ds.Tables[0].Rows.Count != 0)
                return ErrorMessage.AlreadyExitsData;
            
            myGCompanyLib.name= companyName;
            bool ok = optGCompanyLib.Add(myGCompanyLib);
            if (!ok) return ErrorMessage.DBOptError;
            else return ErrorMessage.OK;
        }
        /// <summary>
        /// 删除公司
        /// </summary>
        /// <param name="id">公司ID</param>
        /// <returns></returns>
        public string DeleteCompany(string companyName)
        {
            //检查companyName是否为空
            if (companyName == null || companyName == string.Empty)
                return ErrorMessage.FieldEmpty;

            GMS.ORM.Model.GCompanyLib myGCompanyLib = new GMS.ORM.Model.GCompanyLib();
            GMS.ORM.DAL.GCompanyLib optGCompanyLib = new GMS.ORM.DAL.GCompanyLib();
            //检查companyName是否不存在
            DataSet ds = optGCompanyLib.GetList("name='" + companyName + "'");
            if (ds.Tables[0].Rows.Count == 0)
                return ErrorMessage.NoSuchData;
            int companyID = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
            

            bool ok = optGCompanyLib.Delete(companyID);
            if (!ok) return ErrorMessage.DBOptError;
            else return ErrorMessage.OK;
        }
        /// <summary>
        /// 添加公司类型
        /// </summary>
        /// <param name="companyStyleName">公司类型名</param>
        /// <returns></returns>
        public string AddCompanyStyle(string companyStyleName)
        {
            //检查companyStyleName是否为空
            if (companyStyleName == null || companyStyleName == string.Empty)
                return ErrorMessage.FieldEmpty;

            GMS.ORM.Model.GCompanyStyle myGCompanyStyle = new GMS.ORM.Model.GCompanyStyle();
            GMS.ORM.DAL.GCompanyStyle optGCompanyStyle=new GMS.ORM.DAL.GCompanyStyle();
            //判断公司类型是否存在
            DataSet ds = optGCompanyStyle.GetList("name='" + companyStyleName + "'");
            if (ds.Tables[0].Rows.Count != 0)
                return ErrorMessage.AlreadyExitsData;

            myGCompanyStyle.name = companyStyleName;
            bool ok=optGCompanyStyle.Add(myGCompanyStyle);
            if (!ok) return ErrorMessage.DBOptError;
            else return ErrorMessage.OK;
        }
        /// <summary>
        /// 删除公司类型
        /// </summary>
        /// <param name="id">公司类型ID</param>
        /// <returns></returns>
        public string DeleteCompanyStyle(string companyStyleName)
        {
            
            //检查companyStyleName是否为空
            if (companyStyleName == null || companyStyleName == string.Empty)
                return ErrorMessage.FieldEmpty;

            GMS.ORM.Model.GCompanyStyle myGCompanyStyle = new GMS.ORM.Model.GCompanyStyle();
            GMS.ORM.DAL.GCompanyStyle optGCompanyStyle = new GMS.ORM.DAL.GCompanyStyle();
            //检查companyStyleName是否不存在
            DataSet ds = optGCompanyStyle.GetList("name='" + companyStyleName + "'");
            if (ds.Tables[0].Rows.Count == 0)
                return ErrorMessage.NoSuchData;
            int companyStyleID = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
            

            bool ok = optGCompanyStyle.Delete(companyStyleID);
            if (!ok) return ErrorMessage.DBOptError;
            else return ErrorMessage.OK;
        }
        /// <summary>
        /// 添加工作
        /// </summary>
        /// <param name="Jobname">工作名</param>
        /// <returns></returns>
        public string AddJob(string Jobname)
        {
            //检查Jobname是否为空
            if (Jobname == null || Jobname == string.Empty)
                return ErrorMessage.FieldEmpty;

            GMS.ORM.Model.GJobLib myGJobLib = new GMS.ORM.Model.GJobLib();
            GMS.ORM.DAL.GJobLib optGJobLib = new GMS.ORM.DAL.GJobLib(); 
            //判断工作是否存在
            DataSet ds = optGJobLib.GetList("name='" + Jobname + "'");
            if (ds.Tables[0].Rows.Count != 0)
                return ErrorMessage.AlreadyExitsData;

            myGJobLib.name = Jobname;
            bool ok = optGJobLib.Add(myGJobLib);
            if (!ok) return ErrorMessage.DBOptError;
            else return ErrorMessage.OK;
        }
        /// <summary>
        /// 删除工作
        /// </summary>
        /// <param name="id">工作ID</param>
        /// <returns></returns>
        public string DeleteJob(string Jobname)
        {

            //检查Jobname是否为空
            if (Jobname == null || Jobname == string.Empty)
                return ErrorMessage.FieldEmpty;

            GMS.ORM.Model.GJobLib myGJobLib = new GMS.ORM.Model.GJobLib();
            GMS.ORM.DAL.GJobLib optGJobLib = new GMS.ORM.DAL.GJobLib();
            //检查Jobname是否不存在
            DataSet ds = optGJobLib.GetList("name='" + Jobname + "'");
            if (ds.Tables[0].Rows.Count == 0)  return ErrorMessage.NoSuchData;

            int JobID = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
            
            bool ok = optGJobLib.Delete(JobID);
            if (!ok) return ErrorMessage.DBOptError;
            else return ErrorMessage.OK;
        }
        /// <summary>
        /// 添加英语能力
        /// </summary>
        /// <param name="englishName">英语能力名称</param>
        /// <returns></returns>
        public string AddEnglish(string englishName)
        {
            //检查englishName是否为空
            if (englishName == null || englishName == string.Empty)
                return ErrorMessage.FieldEmpty;

            GMS.ORM.Model.GEnglishLib myGEnglishLib = new GMS.ORM.Model.GEnglishLib();
            GMS.ORM.DAL.GEnglishLib optGEnglishLib = new GMS.ORM.DAL.GEnglishLib();
            //判断英语能力是否存在
            DataSet ds = optGEnglishLib.GetList("name='" + englishName + "'");
            if (ds.Tables[0].Rows.Count != 0)
                return ErrorMessage.AlreadyExitsData;

            myGEnglishLib.id = optGEnglishLib.GetMaxId() + 1;
            myGEnglishLib.name = englishName;
            bool ok = optGEnglishLib.Add(myGEnglishLib);
            if (!ok) return ErrorMessage.DBOptError;
            else return ErrorMessage.OK;
        }
        /// <summary>
        /// 删除英语能力
        /// </summary>
        /// <param name="id">英语能力ID</param>
        /// <returns></returns>
        public string DeleteEnglish(string englishName)
        {
            //检查englishName是否为空
            if (englishName == null || englishName == string.Empty)
                return ErrorMessage.FieldEmpty;

            GMS.ORM.Model.GEnglishLib myGEnglishLib = new GMS.ORM.Model.GEnglishLib();
            GMS.ORM.DAL.GEnglishLib optGEnglishLib = new GMS.ORM.DAL.GEnglishLib();
            //检查englishName是否不存在
            DataSet ds = optGEnglishLib.GetList("name='" + englishName + "'");
            if (ds.Tables[0].Rows.Count == 0)
                return ErrorMessage.NoSuchData;
            int englishID = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
            

            bool ok = optGEnglishLib.Delete(englishID);
            if (!ok) return ErrorMessage.DBOptError;
            else return ErrorMessage.OK;
        }
        /// <summary>
        /// 添加计算机能力
        /// </summary>
        /// <param name="computerName">计算机能力名</param>
        /// <returns></returns>
        public string AddComputer(string computerName)
        {
            //检查computerName是否为空
            if (computerName == null || computerName == string.Empty)
                return ErrorMessage.FieldEmpty;

            GMS.ORM.Model.GComputerLib myGComputerLib = new GMS.ORM.Model.GComputerLib();
            GMS.ORM.DAL.GComputerLib optGComputerLib = new GMS.ORM.DAL.GComputerLib();
            //判断计算机能力是否存在
            DataSet ds = optGComputerLib.GetList("name='" + computerName + "'");
            if (ds.Tables[0].Rows.Count != 0)
                return ErrorMessage.AlreadyExitsData;

            myGComputerLib.name = computerName;
            bool ok = optGComputerLib.Add(myGComputerLib);
            if (!ok) return ErrorMessage.DBOptError;
            else return ErrorMessage.OK;
        }
        /// <summary>
        /// 删除计算机能力
        /// </summary>
        /// <param name="id">计算机能力ID</param>
        /// <returns></returns>
        public string DeleteComputer(string computerName)
        {
            //检查computerName是否为空
            if (computerName == null || computerName == string.Empty)
                return ErrorMessage.FieldEmpty;

            GMS.ORM.Model.GComputerLib myGComputerLib = new GMS.ORM.Model.GComputerLib();
            GMS.ORM.DAL.GComputerLib optGComputerLib = new GMS.ORM.DAL.GComputerLib();
            //检查computerName是否不存在
            DataSet ds = optGComputerLib.GetList("name='" + computerName + "'");
            if (ds.Tables[0].Rows.Count == 0)
                return ErrorMessage.NoSuchData;
            int computerID = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
            

            bool ok = optGComputerLib.Delete(computerID);
            if (!ok) return ErrorMessage.DBOptError;
            else return ErrorMessage.OK;
        }
        /// <summary>
        /// 添加论文状态
        /// </summary>
        /// <param name="id">论文ID</param>
        /// <param name="name">论文名</param>
        /// <returns></returns>
        public string AddDocumentStatus(string name)
        { 
            //检查name是否为空
            if (name == null || name == string.Empty)
                return ErrorMessage.FieldEmpty;

            GMS.ORM.Model.PDocumentStatus myPDocumentStatus = new GMS.ORM.Model.PDocumentStatus();
            GMS.ORM.DAL.PDocumentStatus optPDocumentStatus = new GMS.ORM.DAL.PDocumentStatus();
            //判断论文状态是否已存在
            DataSet ds = optPDocumentStatus.GetList("name='" + name + "'");
            if (ds.Tables[0].Rows.Count != 0)
            {
                myPDocumentStatus.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                myPDocumentStatus.name = ds.Tables[0].Rows[0]["name"].ToString();
                myPDocumentStatus.inUse = 1;//如果存在该状态，则重置inUse为1
                bool ok = optPDocumentStatus.Update(myPDocumentStatus);
                if (!ok) return ErrorMessage.DBOptError;
                return ErrorMessage.OK;
            }
            else
            {
                myPDocumentStatus.id = optPDocumentStatus.GetMaxId() + 1;
                myPDocumentStatus.name = name;
                myPDocumentStatus.inUse = 1;
                bool ok = optPDocumentStatus.Add(myPDocumentStatus);
                if (!ok) return ErrorMessage.DBOptError;
                return ErrorMessage.OK;
            }
        }
        /// <summary>
        /// 删除论文状态
        /// </summary>
        /// <param name="id">论文状态ID</param>
        /// <returns></returns>
        public string DeleteDocumentStatus(string name)
        {
            //检查name是否为空
            if (name == null || name == string.Empty)
                return ErrorMessage.FieldEmpty;

            GMS.ORM.Model.PDocumentStatus myPDocumentStatus = new GMS.ORM.Model.PDocumentStatus();
            GMS.ORM.DAL.PDocumentStatus optPDocumentStatus = new GMS.ORM.DAL.PDocumentStatus();
            //判断论文状态是否不存在
            DataSet ds = optPDocumentStatus.GetList("name='" + name + "'");
            if (ds.Tables[0].Rows.Count == 0)
                return ErrorMessage.NoSuchData;
            else
            {
                myPDocumentStatus.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                if (myPDocumentStatus.id == 0 || myPDocumentStatus.id == 1 || myPDocumentStatus.id == 2)
                    return ErrorMessage.DBOptError;
                else
                {
                    myPDocumentStatus.name = ds.Tables[0].Rows[0]["name"].ToString();
                    myPDocumentStatus.inUse = 0; //如果存在该状态，则重置inUse为0
                    bool ok = optPDocumentStatus.Update(myPDocumentStatus);
                    if (!ok) return ErrorMessage.DBOptError;
                    return ErrorMessage.OK;
                }
            }
        }
        /// <summary>
        /// 更新论文状态
        /// </summary>
        /// <param name="id">论文状态ID</param>
        /// <param name="name">论文状态名</param>
        /// <returns></returns>
        public string UpdateDocumentStatus(int id, string name)
        {
            //检查ID是否不存在
            GMS.ORM.Model.PDocumentStatus myPDocumentStatus = new GMS.ORM.Model.PDocumentStatus();
            GMS.ORM.DAL.PDocumentStatus optPDocumentStatus = new GMS.ORM.DAL.PDocumentStatus();
            if (!optPDocumentStatus.Exists(id))
                return ErrorMessage.NoSuchData;
            
            myPDocumentStatus.id = id;
            myPDocumentStatus.name = name;
            bool ok = optPDocumentStatus.Update(myPDocumentStatus);
            if (!ok) return ErrorMessage.DBOptError;
            else return ErrorMessage.OK;
        }

        /// <summary>
        /// 添加班级
        /// </summary>
        /// <param name="classID">班级ID</param>
        /// <param name="classTeacher">班主任</param>
        /// <param name="classDesc">班级描述</param>
        /// <returns></returns>
        public string AddClass(string classID, string classTeacher, string classDesc)
        {
            //检查classID是否为空,classTeacher以及classDesc都可以为null
            if (classID == null ||classID == string.Empty)
                return ErrorMessage.FieldEmpty;

            GMS.ORM.Model.UClass myUClass = new GMS.ORM.Model.UClass();
            GMS.ORM.DAL.UClass optUClass = new GMS.ORM.DAL.UClass();
            //判断班级是否存在
            DataSet ds = optUClass.GetList("class_id='" +classID + "'");
            if (ds.Tables[0].Rows.Count != 0)
                return ErrorMessage.AlreadyExitsData;

            myUClass.class_id = classID;
            myUClass.class_teacher = classTeacher;
            myUClass.class_desc = classDesc;
            bool ok = optUClass.Add(myUClass);
            if (!ok) return ErrorMessage.DBOptError;
            else return ErrorMessage.OK;
        }
        /// <summary>
        /// 更新班级
        /// </summary>
        /// <param name="classID">班级ID</param>
        /// <param name="classTeacher">班主任</param>
        /// <param name="classDesc">班级描述</param>
        /// <returns></returns>
        public string UpdateClass(string classID, string classTeacher, string classDesc)
        {
            //判断班级是否不存在
            GMS.ORM.Model.UClass myUClass = new GMS.ORM.Model.UClass();
            GMS.ORM.DAL.UClass optUClass = new GMS.ORM.DAL.UClass();
            if (!optUClass.Exists(classID))
                return ErrorMessage.NoSuchData;

            myUClass.class_id = classID;
            myUClass.class_teacher = classTeacher;
            myUClass.class_desc = classDesc;
            bool ok = optUClass.Update(myUClass);
            if (!ok) return ErrorMessage.DBOptError;
            else return ErrorMessage.OK;
        }
        /// <summary>
        /// 删除班级
        /// </summary>
        /// <param name="classID">班级ID</param>
        /// <returns></returns>
        public string DeleteClass(string classID)
        {
            //检查classID是否为空
            if (classID == null || classID == string.Empty)
                return ErrorMessage.FieldEmpty;

            GMS.ORM.Model.UClass myUClass = new GMS.ORM.Model.UClass();
            GMS.ORM.DAL.UClass optUClass = new GMS.ORM.DAL.UClass();
            //判断班级是否不存在
            if(!optUClass.Exists(classID))
                return ErrorMessage.NoSuchData;

            //判断学生列表是否为空
            GMS.ORM.DAL.GStudent myGStudent = new GMS.ORM.DAL.GStudent();
            DataSet ds2 = myGStudent.GetList("class_id='" + classID + "'");
            if (ds2.Tables[0].Rows.Count == 0)
            {
                bool ok = optUClass.Delete(classID);
                if (!ok) return ErrorMessage.DBOptError;
                else return ErrorMessage.OK;
            }
            else return ErrorMessage.DBOptError;
        }
        /// <summary>
        /// 添加学生
        /// </summary>
        /// <param name="studentinfo">学生实体对象</param>
        /// <returns></returns>
        public string AddStudent(StudentInfo studentinfo)
        {
            //检查学生ID是否为空
            if (studentinfo.StdID== null || studentinfo.StdID == string.Empty)
                return ErrorMessage.FieldEmpty;
            
            GMS.ORM.Model.GStudent myGStudent = new GMS.ORM.Model.GStudent();
            GMS.ORM.DAL.GStudent optGStudent = new GMS.ORM.DAL.GStudent();
            //判断学生ID是否存在
            DataSet ds = optGStudent.GetList("std_id='" + studentinfo.StdID + "'");
            if (ds.Tables[0].Rows.Count != 0)
                return ErrorMessage.AlreadyExitsData;
            
            myGStudent.std_id = studentinfo.StdID;
            myGStudent.class_id = studentinfo.ClassID;
            myGStudent.graduate_year = studentinfo.GraduateYear;
            myGStudent.std_name = studentinfo.StdName;
            myGStudent.std_mail = studentinfo.StdMail;
            myGStudent.std_gender = studentinfo.StdGender;
            myGStudent.std_policy = studentinfo.StdPolicy;
            myGStudent.std_hobby = studentinfo.StdHobby;
            bool ok = optGStudent.Add(myGStudent);
            if (!ok) return ErrorMessage.DBOptError;
            else return ErrorMessage.OK;
        }
        /// <summary>
        /// 更新学生
        /// </summary>
        /// <param name="studentinfo">学生实体对象</param>
        /// <returns></returns>
        public string UpdateStudent(StudentInfo studentinfo)
        {
            //检查雪生是否不存在
            GMS.ORM.Model.GStudent myGStudent = new GMS.ORM.Model.GStudent();
            GMS.ORM.DAL.GStudent optGStudent = new GMS.ORM.DAL.GStudent();
            if (!optGStudent.Exists(studentinfo.StdID))
                return ErrorMessage.NoSuchData;

            myGStudent.std_id = studentinfo.StdID;
            myGStudent.class_id = studentinfo.ClassID;
            myGStudent.graduate_year = studentinfo.GraduateYear;
            myGStudent.std_name = studentinfo.StdName;
            myGStudent.std_mail = studentinfo.StdMail;
            myGStudent.std_gender = studentinfo.StdGender;
            myGStudent.std_policy = studentinfo.StdPolicy;
            myGStudent.std_hobby = studentinfo.StdHobby;
            bool ok = optGStudent.Add(myGStudent);
            if (!ok) return ErrorMessage.DBOptError;
            else return ErrorMessage.OK;
        }
        /// <summary>
        /// 删除学生
        /// </summary>
        /// <param name="stdid">学生ID</param>
        /// <returns></returns>
        public string DeleteStudent(string stdid)
        {
            string message=string.Empty;
            bool ok;
            //删除SLogin
            GMS.ORM.DAL.SLogin optSLogin = new GMS.ORM.DAL.SLogin();
            DataSet ds = optSLogin.GetList("idmap='" + stdid + "'");
            if (ds.Tables[0].Rows.Count == 0)
                message = message + stdid + "无登录信息";
            else
            {
                ok = optSLogin.Delete(ds.Tables[0].Rows[0]["name"].ToString());
                if (!ok) message = message + stdid + "删除登录信息出错";
            }
            
            //删除GStudent
            Student myStudent = new Student(stdid);
            //删除englishs
            ArrayList myAL= myStudent.Englishs.GetList();
            if (myAL!=null)
            for (int i = 0; i < myAL.Count; i++) myStudent.Englishs.Delete(decimal.Parse(myAL[i].ToString()));
            myAL.Clear();
            //删除computers
            myAL = myStudent.Computers.GetList();
            if (myAL!=null)
            for (int i = 0; i < myAL.Count; i++) myStudent.Computers.Delete(decimal.Parse(myAL[i].ToString()));
            myAL.Clear();
            //删除jobs
            myAL = myStudent.Jobs.GetList();
            if (myAL != null)
                for (int i = 0; i < myAL.Count; i++) myStudent.Jobs.Delete(decimal.Parse(myAL[i].ToString()));
            myAL.Clear();
            //删除companys
            myAL = myStudent.Companys.GetList();
            if (myAL != null)
                for (int i = 0; i < myAL.Count; i++) myStudent.Companys.Delete(decimal.Parse(myAL[i].ToString()));
            myAL.Clear();
            //删除PGuide
            GMS.ORM.DAL.PGuide optPG = new GMS.ORM.DAL.PGuide();
            ok = optPG.Delete(stdid, myStudent.GraduateYear);
            if (!ok) message = message + stdid + "删除指导信息出错";
            //删除pdenfense
            GMS.ORM.DAL.PDefense optPD = new GMS.ORM.DAL.PDefense();
            ok = optPD.Delete(stdid, myStudent.GraduateYear);
            if (!ok) message = message + stdid + "删除答辩信息出错";
            //删除pfile
            GMS.ORM.DAL.PFile optPF = new GMS.ORM.DAL.PFile();
            DataSet myDS = optPF.GetList("uploader_from='" + stdid + "'or uploader_to='" + stdid + "'");
            if (myDS != null)
                for (int i = 0; i < myDS.Tables[0].Rows.Count; i++) optPF.Delete(decimal.Parse(myDS.Tables[0].Rows[i]["id"].ToString()));
            //删除文件夹
            try
            {
                string file_pre = @"d:\GMSUploadFile";
                DirectoryInfo myDI = new DirectoryInfo(file_pre + @"\" + stdid);
                myDI.Delete(true);
            }
            catch (Exception exp)
            {
                Console.Write(exp.ToString()); 
            }
            //删除GStudent
            GMS.ORM.DAL.GStudent optGStudent = new GMS.ORM.DAL.GStudent();
            ok = optGStudent.Delete(stdid);
            if (!ok) message = message + stdid + "删除学生表出错";
            if (message!=string.Empty) return message;
            return ErrorMessage.OK;
        }
        /// <summary>
        /// 添加教师
        /// </summary>
        /// <param name="staff">教师实体对象</param>
        /// <returns></returns>
        public string AddStaff(Staff staff)
        {
            //检查教师ID是否为空
            if (staff.TeacherId == null ||staff.TeacherId == string.Empty)
                return ErrorMessage.FieldEmpty;

            GMS.ORM.Model.UTeacher myUTeacher = new GMS.ORM.Model.UTeacher();
            GMS.ORM.DAL.UTeacher optUTeacher = new GMS.ORM.DAL.UTeacher();
            //判断教师ID是否存在
            if (optUTeacher.Exists(staff.TeacherId))
                return ErrorMessage.AlreadyExitsData;
          
            myUTeacher.tch_id = staff.TeacherId;
            myUTeacher.tch_name = staff.TeacherName;
            myUTeacher.tch_gender = staff.TeacherGender;
            myUTeacher.tch_office = staff.TeacherOffice;
            myUTeacher.tch_office_tel = staff.TeacherOfficeTel;
            myUTeacher.tch_mobile = staff.TeacherMobile;
            myUTeacher.tch_mail = staff.TeacherMail;
            myUTeacher.tch_award = staff.TeacherAward;
            myUTeacher.tch_field = staff.TeacherField;
            myUTeacher.tch_title = staff.TeacherTitle;
            myUTeacher.if_teacher = staff.IfTeacher ? 1 : 0;
            myUTeacher.if_classteacher = staff.IfClassTeacher ? 1 : 0;
            bool ok = optUTeacher.Add(myUTeacher);
            if (!ok) return ErrorMessage.DBOptError;
            else return ErrorMessage.OK;
        }
        /// <summary>
        /// 更新教师
        /// </summary>
        /// <param name="staff">教师实体对象</param>
        /// <returns></returns>
        public string UpdateStaff(Staff staff)
        {
            GMS.ORM.Model.UTeacher myUTeacher = new GMS.ORM.Model.UTeacher();
            GMS.ORM.DAL.UTeacher optUTeacher=new GMS.ORM.DAL.UTeacher();
            //检查教师ID是否不存在
            if (!optUTeacher.Exists(staff.TeacherId))
               return ErrorMessage.NoSuchData;

            myUTeacher.tch_id = staff.TeacherId;
            myUTeacher.tch_name = staff.TeacherName;
            myUTeacher.tch_gender = staff.TeacherGender;
            myUTeacher.tch_office = staff.TeacherOffice;
            myUTeacher.tch_office_tel = staff.TeacherOfficeTel;
            myUTeacher.tch_mobile = staff.TeacherMobile;
            myUTeacher.tch_mail = staff.TeacherMail;
            myUTeacher.tch_award = staff.TeacherAward;
            myUTeacher.tch_field = staff.TeacherField;
            myUTeacher.tch_title = staff.TeacherTitle;
            myUTeacher.if_teacher = staff.IfTeacher ? 1 : 0;
            myUTeacher.if_classteacher = staff.IfClassTeacher ? 1 : 0;
            bool ok = optUTeacher.Update(myUTeacher);
            if (!ok) return ErrorMessage.DBOptError;
            else return ErrorMessage.OK;
        }
        /// <summary>
        /// 删除教师
        /// </summary>
        /// <param name="id">教师ID</param>
        /// <returns></returns>
        public string DeleteStaff(string id)
        {
            //删除SLogin
            GMS.ORM.DAL.SLogin optSLogin = new GMS.ORM.DAL.SLogin();
            DataSet ds = optSLogin.GetList("idmap='" + id + "'");
            if (ds.Tables[0].Rows.Count == 0)
                return ErrorMessage.NoSuchData;
            bool ok = optSLogin.Delete(ds.Tables[0].Rows[0]["name"].ToString());
            if (!ok) return ErrorMessage.DBOptError;

            //删除UTeacher
            GMS.ORM.DAL.UTeacher optUTeacher = new GMS.ORM.DAL.UTeacher();
            bool ok2 = optUTeacher.Delete(id);

            return ErrorMessage.OK;
        }
        #endregion no static function

        #region static function
        /// <summary>
        /// 获得论文状态列表
        /// </summary>
        /// <returns></returns>
        static public ArrayList GetDocumentStatusLib() 
        {
            GMS.ORM.DAL.PDocumentStatus optPDocumentStatus = new GMS.ORM.DAL.PDocumentStatus();
            DataSet ds = optPDocumentStatus.GetList("inUse=1 ORDER BY name");
            ArrayList arraylist = new ArrayList();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                ListItem newListItem = new ListItem();
                newListItem.Text = ds.Tables[0].Rows[i]["name"].ToString();
                newListItem.Value = ds.Tables[0].Rows[i]["id"].ToString();

                arraylist.Add(newListItem);
            }
            return arraylist;
        }
        /// <summary>
        /// 获得公司列表
        /// </summary>
        /// <returns></returns>
        static public ArrayList GetCompanyLib()
        {
            GMS.ORM.DAL.GCompanyLib optGCompany = new GMS.ORM.DAL.GCompanyLib();
            DataSet ds = optGCompany.GetList("1=1 ORDER BY name");
            ArrayList arraylist = new ArrayList();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                ListItem newListItem = new ListItem();
                newListItem.Text = ds.Tables[0].Rows[i]["name"].ToString();
                newListItem.Value = newListItem.Text;

                arraylist.Add(newListItem);
            }
            return arraylist;
        }
        /// <summary>
        /// 获得公司类型列表
        /// </summary>
        /// <returns></returns>
        static public ArrayList GetCompanyStyleLib()
        {
            GMS.ORM.DAL.GCompanyStyle optGCompanyStyle = new GMS.ORM.DAL.GCompanyStyle();
            DataSet ds = optGCompanyStyle.GetList("1=1 ORDER BY name");
            ArrayList arraylist = new ArrayList();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                ListItem newListItem = new ListItem();
                newListItem.Text = ds.Tables[0].Rows[i]["name"].ToString();
                newListItem.Value = ds.Tables[0].Rows[i]["id"].ToString();

                arraylist.Add(newListItem);
            }
            return arraylist;
        }
        /// <summary>
        /// 获得工作列表
        /// </summary>
        /// <returns></returns>
        static public ArrayList GetJobLib()
        {
            GMS.ORM.DAL.GJobLib optGJobLib = new GMS.ORM.DAL.GJobLib();
            DataSet ds = optGJobLib.GetList("1=1 ORDER BY name");
            ArrayList arraylist = new ArrayList();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                ListItem newListItem = new ListItem();
                newListItem.Text = ds.Tables[0].Rows[i]["name"].ToString();
                newListItem.Value = newListItem.Text;

                arraylist.Add(newListItem);
            }
            return arraylist;
        }
        /// <summary>
        /// 获得英语能力列表
        /// </summary>
        /// <returns></returns>
        static public ArrayList GetEnglishLib()
        {
            GMS.ORM.DAL.GEnglishLib optGEnglishLib = new GMS.ORM.DAL.GEnglishLib();
            DataSet ds = optGEnglishLib.GetList("1=1 ORDER BY name");
            ArrayList arraylist = new ArrayList();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                ListItem newListItem = new ListItem();
                newListItem.Text = ds.Tables[0].Rows[i]["name"].ToString();
                newListItem.Value = newListItem.Text;

                arraylist.Add(newListItem);
            }
            return arraylist;
        }
        /// <summary>
        /// 获得计算机能力列表
        /// </summary>
        /// <returns></returns>
        static public ArrayList GetComputerLib()
        {
            GMS.ORM.DAL.GComputerLib optGComputeLib = new GMS.ORM.DAL.GComputerLib();
            DataSet ds = optGComputeLib.GetList("1=1 ORDER BY name");
            ArrayList arraylist = new ArrayList();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                ListItem newListItem = new ListItem();
                newListItem.Text = ds.Tables[0].Rows[i]["name"].ToString();
                newListItem.Value = newListItem.Text;

                arraylist.Add(newListItem);
            }
            return arraylist;
        }
        /// <summary>
        /// 获得班级列表
        /// </summary>
        /// <returns></returns>
        static public ArrayList GetClassLib()
        {
            GMS.ORM.DAL.UClass optUClass = new GMS.ORM.DAL.UClass();
            DataSet ds = optUClass.GetList("1=1 ORDER BY class_id");
            ArrayList arraylist = new ArrayList();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                ListItem newListItem = new ListItem();
                newListItem.Text = ds.Tables[0].Rows[i]["class_id"].ToString();
                newListItem.Value = newListItem.Text;

                arraylist.Add(newListItem);
            }
            return arraylist;
        }
        /// <summary>
        /// 获取班级列表（前三位）
        /// </summary>
        /// <param name="classID">班级ID前三位</param>
        /// <returns></returns>
        static public ArrayList GetClassLib(string classID)
        {
            GMS.ORM.Model.UClass myUClass=new GMS.ORM.Model.UClass();
            GMS.ORM.DAL.UClass optUClass = new GMS.ORM.DAL.UClass();
            DataSet ds=optUClass.GetList("substring(class_id,1,3)='"+classID+"'  ORDER BY class_id");
            ArrayList arraylist=new ArrayList();
            for(int i=0;i<ds.Tables[0].Rows.Count;i++)
            {
                ListItem newListItem = new ListItem();
                newListItem.Text = ds.Tables[0].Rows[i]["class_id"].ToString();
                newListItem.Value = newListItem.Text;

                arraylist.Add(newListItem);
            }
            return arraylist;
        }
        /// <summary>
        /// 获得论文列表
        /// </summary>
        /// <returns></returns>
        static public ArrayList GetDefenseLib()
        {
            GMS.ORM.DAL.PDefenseLib optPDefenseLib = new GMS.ORM.DAL.PDefenseLib();
            DataSet ds = optPDefenseLib.GetList("1=1 ORDER BY def_time");
            ArrayList arraylist = new ArrayList();
            for(int i=0;i<ds.Tables[0].Rows.Count;i++)
            {
                ListItem newListItem = new ListItem();
                newListItem.Text = "时间：" + ((DateTime)ds.Tables[0].Rows[i]["def_time"]).ToShortDateString() +"   " +((DateTime)ds.Tables[0].Rows[i]["def_time"]).ToShortTimeString() + "   地点：" + ds.Tables[0].Rows[i]["def_room"].ToString();
                newListItem.Value = ds.Tables[0].Rows[i]["def_id"].ToString();

                arraylist.Add(newListItem);
            }
            return arraylist;
        }
        /// <summary>
        /// 获取论文列表（根据年份）
        /// </summary>
        /// <param name="year">毕业年份</param>
        /// <returns></returns>
        static public ArrayList GetDefenseLib(string year)
        {
           
            GMS.ORM.DAL.PDefenseLib optPDefenseLib = new GMS.ORM.DAL.PDefenseLib();
            DataSet ds=optPDefenseLib.GetList("DATEPART(year,def_time)='" + year + "' ORDER BY def_room");
            ArrayList arraylist = new ArrayList();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                ListItem newListItem = new ListItem();
                newListItem.Text = "时间：" + ((DateTime)ds.Tables[0].Rows[i]["def_time"]).ToShortDateString() + "   " + ((DateTime)ds.Tables[0].Rows[i]["def_time"]).ToShortTimeString() + "   地点：" + ds.Tables[0].Rows[i]["def_room"].ToString();
                newListItem.Value = ds.Tables[0].Rows[i]["def_id"].ToString();

                arraylist.Add(newListItem);
            }
            return arraylist;
        }
#endregion static function
    }
}
